package com.feng.springboot01.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class mvcConfig implements WebMvcConfigurer {

    //只是简单地网页跳转可以在这里设置
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //首页
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/index").setViewName("login");
        //没有用的页
        registry.addViewController("/main.html").setViewName("index");

        registry.addViewController("/test").setViewName("test");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginHandler()).addPathPatterns("/**")
                .excludePathPatterns("/","/index","/main")
                .excludePathPatterns("/css/**","/fonts/**","images/**","js/**","/images/**");
    }

    @Bean
    public LoginHandlerInterceptor loginHandler(){
        return  new LoginHandlerInterceptor();
    }
}
